package com.lamada.demo;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 *
 * </p>
 *
 * @author qingshan
 * @since 2020-12-27 17:02
 */
public class stream3 {

    public static void main(String[] args) {
        demo1();
        demo2();
    }

    /**
     * 1. 获取String集合中最长的元素
     */
    static void demo1(){
        List<String> list = Arrays.asList("adnm", "admmt", "pot", "xbangd", "weoujgsd");
        Optional<String> max = list.stream().max(Comparator.comparing(String::length));
        System.out.println("最长的字符串：" + max.get());
    }

    /**
     * 2. 获取String集合中最长的元素
     */
    static void demo2(){
        List<String> list = Arrays.asList("adnm", "admmt", "pot", "xbangd", "weoujgsd");
        Optional<String> max = list.stream().max(Comparator.comparing(String::length));
        System.out.println("最长的字符串：" + max.get());
    }
}
